// JavaScript Document
function alert(msg) {
	$('#errorModel').modal('show');
	document.getElementById("errorModelText").innerHTML = msg;
}

function confirm(msg1, msg2) {
	$('#confirmModel').modal('show');
	document.getElementById("errorModelText").innerHTML = msg1;
	document.getElementById("errorModelText").innerHTML = msg2;
}

function confirm_ok() {
}
// jqgrid自动调节高宽
function doResize() {
	var ss = getPageSize();
	$("#grid-table").jqGrid('setGridWidth', (ss.WinW - 10) * (1 - 0.1667) - 80)
			.jqGrid('setGridHeight', "undifined");
}

function getPageSize() {
	var winW;
	if (window.innerHeight) {// all except IE
		winW = window.innerWidth;
	} else if (document.documentElement
			&& document.documentElement.clientHeight) {// IE 6 Strict Mode
		winW = document.documentElement.clientWidth;
	} else if (document.body) { // other
		winW = document.body.clientWidth;
	} // for small pages with total size less then the viewport
	return {
		WinW : winW,
	};
}
$(document)
		.ready(
				function() {
					$(".validate")
							.submit(
									function(e) {
										var form = e.target;
										for ( var i = 0; i < form.length; i++) {
											var input = form[i];
											var name = input.name;
											var value = input.value;
											var rule = input.attributes["rule"].nodeValue;
											if (!(name.length == 0 || name == "undefined")) {
												var check = eval("(" + rule
														+ ")");
												try {
													var required = check.required;
													var max = check.max;
													if(!max.match(/\d+/))
														max = 255;
													var min = check.min;
													if(!min.match(/\d+/))
														min = 0;
													var reg = check.reg;
													if(reg.length==0)
														reg = /^.*$/;
													if(required=="required"&&(value.length==0||value=="undefined"))
													{
														input
														.insertAdjacentHTML(
																"afterEnd",
																"<span class='help-block'>不能为空</span>");
														return false;
													}else if(value.length >max||value.length<min){
														input
														.insertAdjacentHTML(
																"afterEnd",
																"<span class='help-block'>长度范围应该在"+min+","+max+"</span>");
														return false;
													}
													else if(!value.match(reg))
													{
														input
														.insertAdjacentHTML(
																"afterEnd",
																"<span class='help-block'>格式错误</span>");
														return false;
													}
												} catch (e) {
												}finally{
													$('span',this).fadeOut(2500);
												}
											}
										}
									});
				});
/**
 * 
 */
// 导出
function exportexcel() {
	var selectedIds = $("#grid-table").jqGrid("getGridParam", "selarrrow");
	if (selectedIds.length == 0)
		alert("请至少选择一行数据");
	else {
		var obj = new Array();
		var length = selectedIds.length;
		for (var i = 0; i < length; i++) {
			obj[i] = $("#grid-table").jqGrid("getRowData", selectedIds[i]);
		}
		var form = $("<form>"); // 定义一个form表单
		form.attr('method', 'post');
		form.attr('action', "export_index");
		var input = $('<input>');
		input.attr('type', 'hidden');
		input.attr('name', 'excel_json');
		input.attr('value', JSON.stringify(obj));
		$('body').append(form); // 将表单放置在web中
		form.append(input); // 将查询参数控件提交到表单上
		form.submit(); // 表单提交
	}
}
